﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace STHPMS1.Common.C_Extension
{
    public static class DoubleExt
    {
        /// <summary>
        /// 获取桩号的K值 
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static double StakeK(this double d)
        {
            return Math.Round(d / 1000);
        }
        /// <summary>
        /// 获取桩号的扩展值
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static double StakeExt(this double d)
        {
            return Math.IEEERemainder(d, 1000);
        }

        /// <summary>
        /// 将空的浮点数转换为浮点数
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static double ToD(this double? d)
        {
            return (double)d;
        }

        /// <summary>
        /// 将空的整数转换为整数
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static int ToI(this int? d)
        {
            return (int)d;
        }

        /// <summary>
        /// 输出为桩号
        /// </summary>
        /// <param name="mp"></param>
        /// <returns></returns>
        public static string PrintStake(this double? mp)
        {
            string val = "";
            if (mp != null)
            {
                double d=(double)mp;
                val = d.PrintStake();
            }
            return val;
        }

        public static string PrintStake(this double mp)
        {
            string val = "";
            double k = Math.Floor(mp / 1000);
            double r = mp % 1000;

            if (r == 0)
                val = string.Format("K{0}+000", k);
            else
                val = string.Format("K{0}+{1:000.00}", k, r);
            return val;
        }
    }
}
